class KnowledgeSource:
    def __init__(self, blackboard):
        self.blackboard = blackboard

    def read(self):
        pass

    def write(self):
        pass
class Blackboard:
    def __init__(self):
        self.symptoms = []
        self.medical_history = {}
        self.lab_results = {}
        self.diagnosis = None

class SymptomChecker(KnowledgeSource):
    def __init__(self, blackboard):
        self.blackboard = blackboard

    def process(self, input_data):
        self.blackboard.symptoms = input_data['symptoms']

class MedicalConditionDatabase(KnowledgeSource):
    def __init__(self, blackboard):
        self.blackboard = blackboard

    def process(self, input_data):
        medical_conditions = {
            ('fever', 'cough'): 'You may have the flu.',
            ('fever', 'rash'): 'You may have measles.',
            ('chest pain', 'shortness of breath'): 'You may have a heart attack.'
        }
        symptoms_tuple = tuple(input_data['symptoms'])
        self.blackboard.diagnosis = medical_conditions.get(symptoms_tuple, 'No diagnosis found in medical condition database.')

class DiagnosticRules(KnowledgeSource):
    def __init__(self, blackboard):
        self.blackboard = blackboard

    def process(self, input_data):
        if 'fever' in input_data['symptoms'] and 'none' in input_data['medical_history'].values():
            self.blackboard.diagnosis = 'You may have a viral infection.'

class ControlMechanism:
    def __init__(self, blackboard, knowledge_sources):
        self.blackboard = blackboard
        self.knowledge_sources = knowledge_sources

    def trigger(self):
        for knowledge_source in self.knowledge_sources:
            knowledge_source.process(self.blackboard.__dict__)

if __name__ == '__main__':
    blackboard = Blackboard()
    symptom_checker = SymptomChecker(blackboard)
    medical_condition_database = MedicalConditionDatabase(blackboard)
    diagnostic_rules = DiagnosticRules(blackboard)

    # Add the DiagnosticRules instance to the knowledge_sources list
    knowledge_sources = [symptom_checker, medical_condition_database, diagnostic_rules]

    
    blackboard.symptoms = ['fever', 'cough']
    blackboard.medical_history = {'allergies': 'none', 'medications': 'none'}
    blackboard.lab_results = {'blood_pressure': 'normal', 'temperature': '101'}

    control_mechanism = ControlMechanism(blackboard, knowledge_sources)

    # Call the trigger method of the ControlMechanism instance
    control_mechanism.trigger()

    # Print the suggested diagnosis
    print(blackboard.diagnosis)




# # Example usage
# blackboard = Blackboard()
# symptom_checker = SymptomChecker(blackboard)
# medical_condition_database = MedicalConditionDatabase(blackboard)
# diagnostic_rules = DiagnosticRules(blackboard)
# knowledge_sources = [symptom_checker, medical_condition_database, diagnostic_rules]
# control_mechanism = ControlMechanism(blackboard, knowledge_sources)

# blackboard.symptoms = ['fever', 'cough']
# blackboard.medical_history = {'allergies': 'none', 'medications': 'none'}
# blackboard.lab_results = {'blood_pressure': 'normal', 'temperature': '101'}

# control_mechanism.trigger()



# blackboard = Blackboard()
# symptom_checker = SymptomChecker(blackboard)
# medical_condition_database = MedicalConditionDatabase(blackboard)
# diagnostic_rules = DiagnosticRules(blackboard)

# # Add the DiagnosticRules instance to the knowledge_sources list
# knowledge_sources = [symptom_checker, medical_condition_database, diagnostic_rules]

# control_mechanism = ControlMechanism(blackboard, knowledge_sources)


# control_mechanism.trigger()

# print(blackboard.diagnosis) # prints the suggested diagnosis based on the input data

